﻿using System;
using System.Reflection;

namespace UtilZ.Dotnet.Ex.Json
{
    /// <summary>
    /// json值转换器接口
    /// </summary>
    public interface IJsonValueConverter
    {
        /// <summary>
        /// 值是否需要添加双引号[true:添加双引号;false:不添加双引号]
        /// </summary>
        bool HasAddDoubleQuotes { get; }

        /// <summary>
        /// 尝试将对象值转换为json值[转换成功返回true,失败返回false]
        /// </summary>
        /// <param name="memberInfo">成员信息</param>
        /// <param name="valueType">值类型</param>
        /// <param name="owner">成员所属对象</param>
        /// <param name="value">属性或字段值</param>
        /// <param name="jsonValue">成员值</param>
        /// <returns>转换成功返回true,失败返回false</returns>
        bool TryConvertTo(MemberInfo memberInfo, Type valueType, object owner, object value, out string jsonValue);

        /// <summary>
        /// 尝试将json值转换为对象值[转换成功返回true,失败返回false]
        /// </summary>
        /// <param name="memberInfo">成员信息</param>
        /// <param name="valueType">值类型</param>
        /// <param name="owner">成员所属对象</param>
        /// <param name="jsonValue">json值</param>
        /// <param name="value">对象值</param>
        /// <returns>转换成功返回true,失败返回false</returns>
        bool TryConvertFrom(MemberInfo memberInfo, Type valueType, object owner, string jsonValue, out object value);
    }
}
